package com.wanxi.dangdang.mapper;

import com.wanxi.dangdang.model.pojo.BUser;
import com.wanxi.dangdang.model.vo.BUserCheckVo;
import com.wanxi.dangdang.model.vo.BUserPageVo;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface UserMapper {
    @Select("select id, username,real_name,phone,email,id_card,user_type,business_license_picture,head_picture from b_user where id = #{id}")
    BUser findById(@Param("id") Long id);

    @Update("update b_user set password = #{password} where id = #{id}")
    void updatePassById(BUser bUser);

    @Update("update b_user set update_time = #{updateTime} ,delete_status = #{deleteStatus} where id = #{id}")
    void deleteById(BUser bUser);

    @Select("select id,password, username,real_name,phone,email,id_card,user_type,business_license_picture,head_picture from b_user where phone = #{account}")
    BUser findByAccount(@Param("account") String account);

    @Insert("insert into b_user (username,real_name,password,phone,email,id_card,user_type,business_license_picture,head_picture,create_time,update_time)" +
            " value (#{username},#{realName},#{password},#{phone},#{email},#{idCard},#{userType},#{businessLicensePicture},#{headPicture},NOW(),NOW()) ")
    @Options(useGeneratedKeys=true, keyProperty="id" ,keyColumn = "id")
    void add(BUser bUser);

    @Update("update b_user set username = #{username} ,real_name = #{realName} ,phone = #{phone} ,email = #{email} ,id_card = #{idCard} ,user_type = #{userType} ,business_license_picture = #{businessLicensePicture} ,head_picture = #{headPicture} ,update_time = NOW() where id =#{id}")
    void updateAllById(BUser bUser);

    List<BUser> findAll(BUserPageVo bUserPageVo);

    @Select("select id, username,real_name,phone,email,id_card,user_type,business_license_picture,head_picture from b_user where phone = #{account}")
    BUserCheckVo checkAccount(@Param("account") String account);

}
